
//
//  YDBindBankCardController.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/13.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDBindBankCardController.h"
#import "YDBankCardFormatter.h"



@interface YDBindBankCardController ()<UITextFieldDelegate>
//卡号输入格式
@property (strong, nonatomic) YDBankCardFormatter *cardNoFormatter;
//持卡人下划线
@property (nonatomic , weak) UIView *cradManLineView;
//身份证下划线
@property (nonatomic , weak) UIView *idCradLineView;
//银行卡下划线
@property (nonatomic , weak) UIView *cradLineView;
//手机号下划线
@property (nonatomic , weak) UIView *phoneLineView;
//验证码下划线
@property (nonatomic , weak) UIView *codeLineView;

//持卡人label
@property (nonatomic , weak) UILabel *cradManLabel;
//姓名输入框
@property (nonatomic , weak) UITextField *nameTextField;

//身份证label
@property (nonatomic , weak) UILabel *idCradLabel;
//姓名输入框
@property (nonatomic , weak) UITextField *idCradTextField;

//银行卡label
@property (nonatomic , weak) UILabel *cradLabel;
//银行卡输入框
@property (nonatomic , weak) UITextField *cradTextField;


//手机号label
@property (nonatomic , weak) UILabel *phoneLabel;
//手机号输入框
@property (nonatomic , weak) SYPhoneTextField *phoneTextField;

//验证码输入框
@property (nonatomic , weak) UITextField *codeTextField;

//验证码按钮
@property (nonatomic , weak) SYNoHeightedButton *codeButton;

//提示文字
@property (nonatomic , weak) UILabel *postLabel;

//确认按钮
@property (nonatomic , weak) SYNoHeightedButton *sureButton;

//输入的信息
@property (nonatomic , copy) NSString *name;
@property (nonatomic , copy) NSString *idCard;
@property (nonatomic , copy) NSString *bankCard;
@property (nonatomic , copy) NSString *phone;
@property (nonatomic , copy) NSString *code;

@end

@implementation YDBindBankCardController

- (YDBankCardFormatter *)cardNoFormatter
{
    if(_cardNoFormatter == nil) {
        _cardNoFormatter = [[YDBankCardFormatter alloc] init];
    }
    return _cardNoFormatter;
}

-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"绑定银行卡";
    //给界面添加点击手势，点击退出编辑
    [self dismissKeyBoard];
    
    [self addChildViews];
    
    
    //给输入框添加监听，控制登录按钮是否可以点击
    [self.nameTextField addTarget:self action:@selector(textchange) forControlEvents:UIControlEventAllEditingEvents];
    [self.idCradTextField addTarget:self action:@selector(textchange) forControlEvents:UIControlEventAllEditingEvents];
    [self.cradTextField addTarget:self action:@selector(textchange) forControlEvents:UIControlEventAllEditingEvents];
    [self.phoneTextField addTarget:self action:@selector(textchange) forControlEvents:UIControlEventAllEditingEvents];
    [self.codeTextField addTarget:self action:@selector(textchange) forControlEvents:UIControlEventAllEditingEvents];
    
}

//添加子控件
-(void)addChildViews
{
    [self cradManLineView];
    [self idCradLineView];
    [self cradLineView];
    [self phoneLineView];
    [self codeLineView];
    //
    [self cradManLabel];
    [self nameTextField];
    
    
    [self idCradLabel];
    [self idCradTextField];
    
    [self cradLabel];
    [self cradTextField];
    
    [self phoneLabel];
    [self phoneTextField];
    
     [self codeButton];
    
    [self codeTextField];
    
    [self postLabel];
    
    [self sureButton];
    
}

//点击事件
-(void)codeButtonClick
{
    [self.view endEditing:YES];
    self.name = self.nameTextField.text;
    self.idCard = self.idCradTextField.text;
    self.bankCard = [self.cradTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    self.phone = [self.phoneTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    //判断手机号是不是符合规范 持卡人有咩有输入，身份证号有咩有
    
    if (!self.name) {
        [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                        WithType:NavTipsViewTypeMessage
                                                            text:@"请输入持卡人姓名"
                                                      isExistNav:YES];
        
    }else if (![NSString checkUserIdCard:self.idCard]){
        [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                        WithType:NavTipsViewTypeMessage
                                                            text:@"请输入有效的身份证号码"
                                                      isExistNav:YES];
        return;
    }else if (![NSString isPhoneNumber:self.phone]){
        [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                        WithType:NavTipsViewTypeMessage
                                                            text:@"请输入正确的手机号"
                                                      isExistNav:YES];
        return;
//    }else if (![NSString checkBankCard:self.bankCard]){
//        [[SYProgressHUD sharedInstance] showSVErrorWithImageName:@"" andText:@"请输入正确的持卡人的银行卡号"];
//        [[SYProgressHUD sharedInstance] dismissSVWithTime:1];
//        return;
//    }
    }else{
        [self getCodeRequest];
        [self.codeButton openCountdown];
    }
    
}
-(void)sureButtonClick:(SYNoHeightedButton *)button
{
    [self.view endEditing:YES];
    
    self.name = self.nameTextField.text;
    self.idCard = self.idCradTextField.text;
    self.bankCard = [self.cradTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    self.phone = [self.phoneTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    self.code = self.codeTextField.text;
    
    if (!self.name) {
        [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                        WithType:NavTipsViewTypeMessage
                                                            text:@"请输入持卡人姓名"
                                                      isExistNav:YES];
    }else if (![NSString checkUserIdCard:self.idCard]){
        [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                        WithType:NavTipsViewTypeMessage
                                                            text:@"请输入有效的身份证号码"
                                                      isExistNav:YES];
        return;
    }else if (![NSString isPhoneNumber:self.phone]){
;
        [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                        WithType:NavTipsViewTypeMessage
                                                            text:@"请输入正确的手机号"
                                                      isExistNav:YES];
        return;

    }else if (![NSString checkBankCard:self.bankCard]){

        [[NavTipsView defaultTipsView] showTipsBannerInView:self.view WithType:NavTipsViewTypeMessage text:@"请输入正确的持卡人的银行卡号" isExistNav:YES];
        return;

    }
    else if (![NSString isAllNum:self.code]){

        [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                        WithType:NavTipsViewTypeMessage
                                                            text:@"请输入正确的验证码"
                                                      isExistNav:YES];
        
        return;
    }else{
        [self sendBindBnakInformation];
    }
    
}
//获取验证码
-(void)getCodeRequest
{
    [[SYProgressHUD sharedInstance] showMBHudWithSting:kLoadingText];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    
    [dict setObject:self.phone forKey:@"phone"];
    [dict setObject:@(3) forKey:@"type"];
    
    [BaseNetRequest sessionRequestWithparameters:dict method:POSTMethod requstType:GetCodeNumber WithSuccessBlock:^(NSDictionary *resultDict) {
        [[SYProgressHUD sharedInstance] dismissMBWithTime:0];
        DDLog(@"成功信息%@",resultDict);
        DDLog(@"%@",resultDict[@"message"]);
        if ([resultDict[@"code"] integerValue] == 200) {
            self.codeButton.isSuccessSendCode = YES;
        }else{
            self.codeButton.isSuccessSendCode = NO;
        }
        
        if ([resultDict[@"code"] integerValue] == 200) {//成功
            [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                            WithType:NavTipsViewTypeSuccess
                                                                text:@"验证码已发送，请注意查收"
                                                          isExistNav:YES];
        }else{
            [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                            WithType:NavTipsViewTypeMessage
                                                                text:@"验证码发送失败，请稍后重试"
                                                          isExistNav:YES];
        }
    } failBlock:^(NSError *error) {
        DDLog(@"error = %@",error)
        self.codeButton.isSuccessSendCode = NO;
        [[SYProgressHUD sharedInstance] dismissMBWithTime:0];
        [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                        WithType:NavTipsViewTypeMessage
                                                            text:@"验证码发送失败，请稍后重试"
                                                      isExistNav:YES];
    }];

}

//发送绑卡信息
-(void)sendBindBnakInformation
{
    [[SYProgressHUD sharedInstance] showMBHudWithSting:kLoadingText];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:self.phone forKey:@"phone"];
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:self.idCard forKey:@"idCard"];
    [dict setObject:self.code forKey:@"verificationCode"];
    [dict setObject:self.bankCard forKey:@"bankCard"];
    [BaseNetRequest sessionRequestWithparameters:dict method:POSTMethod requstType:BindBankCard WithSuccessBlock:^(NSDictionary *resultDict) {
        [[SYProgressHUD sharedInstance] dismissMBWithTime:0];
        DDLog(@"绑卡成功信息 = %@",resultDict);
        DDLog(@"绑卡信息提示 = %@",resultDict[@"message"]);
        if ([resultDict[@"code"] integerValue] == 200) {//注册成功
            
            [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                            WithType:NavTipsViewTypeSuccess
                                                                text:@"绑定银行卡成功"
                                                          isExistNav:YES];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:YES];
            });
            
        }else{
            [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                            WithType:NavTipsViewTypeMessage
                                                                text:resultDict[@"message"]
                                                          isExistNav:YES];
        }
    } failBlock:^(NSError *error) {
        DDLog(@"%@",error)
        [[SYProgressHUD sharedInstance] dismissMBWithTime:0];
        [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                        WithType:NavTipsViewTypeMessage
                                                            text:@"绑卡出错，请稍后重试~"
                                                      isExistNav:YES];
    }];

}

-(void)textchange
{
    self.codeButton.enabled = self.nameTextField.text.length && self.idCradTextField.text.length && self.cradTextField.text.length && self.phoneTextField.text.length;
    self.sureButton.enabled = self.nameTextField.text.length && self.idCradTextField.text.length && self.cradTextField.text.length && self.phoneTextField.text.length && self.codeTextField.text.length;
}


#pragma UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
{
    if (textField == _phoneTextField) {
        NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
        if ([toBeString length] > 13) {
            
            return NO;
        }
    
    }
    //身份证
    if (textField == _idCradTextField) {
        NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
        if ([toBeString length] > 18) {
            
            return NO;
        }
    }
    
    if (textField == _cradTextField) {
        [self.cardNoFormatter bankField:textField shouldChangeCharactersInRange:range replacementString:string];
        return NO;
    }
    
    if([string hasSuffix:@" "]){
        // 忽视空格
        return NO;
    }else{
        return YES;
    }
    return YES;
}

///**********持卡人下划线********///
-(UIView *)cradManLineView
{
    if (_cradManLineView == nil) {
        UIView *cradManLineView = [[UIView alloc] init];
        [self.view addSubview:cradManLineView];
        //236 231 231
        cradManLineView.backgroundColor = NumberColor(236, 231, 231);
        [cradManLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(rate375(325)));
            make.centerX.equalTo(self.view);
            make.height.equalTo(@1);
            if (isPhoneX) {
                make.top.equalTo(self.view).offset(rateX812(60));
            }else{
                make.top.equalTo(self.view).offset(rate750(50));
            }
        }];
        
        _cradManLineView = cradManLineView;
    }
    return _cradManLineView;
}
///**********身份证下划线********///
-(UIView *)idCradLineView
{
    if (_idCradLineView == nil) {
        UIView *idCradLineView = [[UIView alloc] init];
        [self.view addSubview:idCradLineView];
        //236 231 231
        idCradLineView.backgroundColor = NumberColor(236, 231, 231);
        [idCradLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(rate375(325)));
            make.centerX.equalTo(self.view);
            make.height.equalTo(@1);
            if (isPhoneX) {
                make.top.equalTo(self.cradManLineView.mas_bottom).offset(rateX812(50));
            }else{
                make.top.equalTo(self.cradManLineView.mas_bottom).offset(rate750(50));
            }
        }];
        
        _idCradLineView = idCradLineView;
    }
    return _idCradLineView;
}
///**********银行卡下划线********///
-(UIView *)cradLineView
{
    if (_cradLineView == nil) {
        UIView *cradLineView = [[UIView alloc] init];
        [self.view addSubview:cradLineView];
        //236 231 231
        cradLineView.backgroundColor = NumberColor(236, 231, 231);
        [cradLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(rate375(325)));
            make.centerX.equalTo(self.view);
            make.height.equalTo(@1);
            if (isPhoneX) {
                make.top.equalTo(self.idCradLineView.mas_bottom).offset(rateX812(50));
            }else{
                make.top.equalTo(self.idCradLineView.mas_bottom).offset(rate750(50));
            }
        }];
        
        _cradLineView = cradLineView;
    }
    return _cradLineView;
}
///**********手机号下划线********///
-(UIView *)phoneLineView
{
    if (_phoneLineView == nil) {
        UIView *phoneLineView = [[UIView alloc] init];
        [self.view addSubview:phoneLineView];
        //236 231 231
        phoneLineView.backgroundColor = NumberColor(236, 231, 231);
        [phoneLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(rate375(325)));
            make.centerX.equalTo(self.view);
            make.height.equalTo(@1);
            if (isPhoneX) {
                make.top.equalTo(self.cradLineView.mas_bottom).offset(rateX812(50));
            }else{
                make.top.equalTo(self.cradLineView.mas_bottom).offset(rate750(50));
            }
        }];
        
        _phoneLineView = phoneLineView;
    }
    return _phoneLineView;
}
///**********验证码下划线********///
-(UIView *)codeLineView
{
    if (_codeLineView == nil) {
        UIView *codeLineView = [[UIView alloc] init];
        [self.view addSubview:codeLineView];
        //236 231 231
        codeLineView.backgroundColor = NumberColor(236, 231, 231);
        [codeLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.cradLineView);
            make.right.equalTo(self.view).offset(-rate375(175));
            make.height.equalTo(@1);
            if (isPhoneX) {
                make.top.equalTo(self.phoneLineView.mas_bottom).offset(rateX812(50));
            }else{
                make.top.equalTo(self.phoneLineView.mas_bottom).offset(rate750(50));
            }
        }];
        
        _codeLineView = codeLineView;
    }
    return _codeLineView;
}

//持卡人
-(UILabel *)cradManLabel
{
    if (_cradManLabel == nil) {
        UILabel *cradManLabel = [[UILabel alloc] init];
        [self.view addSubview:cradManLabel];
//        、、129 128 129
        cradManLabel.textColor = NumberColor(129, 128, 129);
        cradManLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        cradManLabel.textAlignment = NSTextAlignmentLeft;
        cradManLabel.text = @"持卡人";
        [cradManLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.cradManLineView);
            if (isPhoneX) {
                make.bottom.equalTo(self.cradManLineView.mas_top).offset(-rateX812(15));
            }else{
                make.bottom.equalTo(self.cradManLineView.mas_top).offset(-rate750(15));
            }
        }];
        _cradManLabel = cradManLabel;
    }
    return _cradManLabel;
}
//持卡人输入框
-(UITextField *)nameTextField
{
    if (_nameTextField == nil) {
        UITextField *nameTextField = [[UITextField alloc] init];
        [self.view addSubview:nameTextField];
        nameTextField.textColor = [UIColor blackColor];
        nameTextField.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        nameTextField.placeholder = @"请输入姓名";
        nameTextField.backgroundColor = [UIColor clearColor];
        nameTextField.borderStyle = UITextBorderStyleNone;
        nameTextField.textAlignment = NSTextAlignmentLeft;
        nameTextField.keyboardType = UIKeyboardTypeDefault;
        nameTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
        nameTextField.keyboardAppearance=UIKeyboardAppearanceDefault;
        nameTextField.returnKeyType =UIReturnKeyDone;
        [nameTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
        [nameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.cradManLabel);
            make.left.equalTo(self.cradManLabel.mas_right).offset(rate375(20));
            make.right.equalTo(self.cradManLineView);
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(20)));
            }else{
                make.height.equalTo(@(rate750(20)));
            }
        }];
        nameTextField.tintColor = [UIColor blackColor];
        nameTextField.delegate = self;
        
//        [nameTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        
        _nameTextField = nameTextField;
    }
    return _nameTextField;
}

//身份证
-(UILabel *)idCradLabel
{
    if (_idCradLabel == nil) {
        UILabel *idCradLabel = [[UILabel alloc] init];
        [self.view addSubview:idCradLabel];
        //        、、129 128 129
        idCradLabel.textColor = NumberColor(129, 128, 129);
        idCradLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        idCradLabel.textAlignment = NSTextAlignmentLeft;
        idCradLabel.text = @"身份证";
        [idCradLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.idCradLineView);
            if (isPhoneX) {
                make.bottom.equalTo(self.idCradLineView.mas_top).offset(-rateX812(15));
            }else{
                make.bottom.equalTo(self.idCradLineView.mas_top).offset(-rate750(15));
            }
        }];
        _idCradLabel = idCradLabel;
    }
    return _idCradLabel;
}

-(UITextField *)idCradTextField
{
    if (_idCradTextField == nil) {
        UITextField *idCradTextField = [[UITextField alloc] init];
        [self.view addSubview:idCradTextField];
        idCradTextField.textColor = [UIColor blackColor];
        idCradTextField.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        idCradTextField.placeholder = @"请输入正确的身份证号";
        idCradTextField.backgroundColor = [UIColor clearColor];
        idCradTextField.borderStyle = UITextBorderStyleNone;
        idCradTextField.textAlignment = NSTextAlignmentLeft;
        idCradTextField.keyboardType = UIKeyboardTypeDefault;
        idCradTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
        idCradTextField.keyboardAppearance=UIKeyboardAppearanceDefault;
        idCradTextField.returnKeyType =UIReturnKeyDone;
        [idCradTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
        [idCradTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.idCradLabel);
            make.left.equalTo(self.idCradLabel.mas_right).offset(rate375(20));
            make.right.equalTo(self.idCradLineView);
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(20)));
            }else{
                make.height.equalTo(@(rate750(20)));
            }
        }];
        idCradTextField.tintColor = [UIColor blackColor];
        idCradTextField.delegate = self;
        
        //        [idCradTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        
        _idCradTextField = idCradTextField;
    }
    return _idCradTextField;
}


//银行卡
-(UILabel *)cradLabel
{
    if (_cradLabel == nil) {
        UILabel *cradLabel = [[UILabel alloc] init];
        [self.view addSubview:cradLabel];
        //        、、129 128 129
        cradLabel.textColor = NumberColor(129, 128, 129);
        cradLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        cradLabel.textAlignment = NSTextAlignmentLeft;
        cradLabel.text = @"银行卡";
        [cradLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.cradLineView);
            if (isPhoneX) {
                make.bottom.equalTo(self.cradLineView.mas_top).offset(-rateX812(15));
            }else{
                make.bottom.equalTo(self.cradLineView.mas_top).offset(-rate750(15));
            }
        }];
        _cradLabel = cradLabel;
    }
    return _cradLabel;
}

-(UITextField *)cradTextField
{
    if (_cradTextField == nil) {
        UITextField *cradTextField = [[UITextField alloc] init];
        [self.view addSubview:cradTextField];
        cradTextField.textColor = [UIColor blackColor];
        cradTextField.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        cradTextField.placeholder = @"请输入正确的银行卡号";
        cradTextField.backgroundColor = [UIColor clearColor];
        cradTextField.borderStyle = UITextBorderStyleNone;
        cradTextField.textAlignment = NSTextAlignmentLeft;
        cradTextField.keyboardType = UIKeyboardTypeNumberPad;
        cradTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
        cradTextField.keyboardAppearance=UIKeyboardAppearanceDefault;
        cradTextField.returnKeyType =UIReturnKeyDone;
        [cradTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
        [cradTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.cradLabel);
            make.left.equalTo(self.cradLabel.mas_right).offset(rate375(20));
            make.right.equalTo(self.cradLineView);
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(20)));
            }else{
                make.height.equalTo(@(rate750(20)));
            }
        }];
        cradTextField.tintColor = [UIColor blackColor];
        cradTextField.delegate = self;
        
        //        [cradTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        
        _cradTextField = cradTextField;
    }
    return _cradTextField;
}

//手机号
-(UILabel *)phoneLabel
{
    if (_phoneLabel == nil) {
        UILabel *phoneLabel = [[UILabel alloc] init];
        [self.view addSubview:phoneLabel];
        //        、、129 128 129
        phoneLabel.textColor = NumberColor(129, 128, 129);
        phoneLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        phoneLabel.textAlignment = NSTextAlignmentLeft;
        phoneLabel.text = @"手机号";
        [phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.phoneLineView);
            if (isPhoneX) {
                make.bottom.equalTo(self.phoneLineView.mas_top).offset(-rateX812(15));
            }else{
                make.bottom.equalTo(self.phoneLineView.mas_top).offset(-rate750(15));
            }
        }];
        _phoneLabel = phoneLabel;
    }
    return _phoneLabel;
}
-(SYPhoneTextField *)phoneTextField
{
    if (_phoneTextField == nil) {
        SYPhoneTextField *phoneTextField = [[SYPhoneTextField alloc] init];
        [self.view addSubview:phoneTextField];
        phoneTextField.textColor = [UIColor blackColor];
        phoneTextField.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        phoneTextField.placeholder = @"请输入手机号码";
        phoneTextField.backgroundColor = [UIColor clearColor];
        phoneTextField.borderStyle = UITextBorderStyleNone;
        phoneTextField.textAlignment = NSTextAlignmentLeft;
        phoneTextField.keyboardType = UIKeyboardTypeNumberPad;
        phoneTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
        phoneTextField.keyboardAppearance=UIKeyboardAppearanceDefault;
        phoneTextField.returnKeyType =UIReturnKeyDone;
        [phoneTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
        [phoneTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.phoneLabel);
            make.left.equalTo(self.phoneLabel.mas_right).offset(rate375(20));
            make.right.equalTo(self.phoneLineView);
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(20)));
            }else{
                make.height.equalTo(@(rate750(20)));
            }
        }];
        phoneTextField.tintColor = [UIColor blackColor];
        phoneTextField.delegate = self;
        
        //        [phoneTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        
        _phoneTextField = phoneTextField;
    }
    return _phoneTextField;
}

//获取验证码按钮
-(SYNoHeightedButton *)codeButton
{
    if (_codeButton == nil) {
        SYNoHeightedButton *codeButton = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self.view addSubview:codeButton];
        codeButton.enabled = NO;
        codeButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        [codeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [codeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateDisabled];
        [codeButton setBackgroundImage:[UIImage imageWithColor:zhidainMainColor] forState:UIControlStateNormal];
        [codeButton setBackgroundImage:[UIImage imageWithColor:zhidianAlprColor(0.3)] forState:UIControlStateDisabled];
        [codeButton setTitle:@"发送验证码" forState:UIControlStateNormal];
        [codeButton setTitle:@"发送验证码" forState:UIControlStateDisabled];
        codeButton.titleLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        [codeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.right.equalTo(self.cradLineView);
            make.width.equalTo(@(rate375(140)));
            make.bottom.equalTo(self.codeLineView.mas_top);
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(40)));
            }else{
                make.height.equalTo(@(rate750(40)));
            }
            
        }];
        [codeButton addTarget:self action:@selector(codeButtonClick) forControlEvents:UIControlEventTouchDown];
        codeButton.layer.cornerRadius = 5;
        codeButton.layer.masksToBounds = YES;
        
        _codeButton = codeButton;
    }
    return _codeButton;
}

//验证码输入框
-(UITextField *)codeTextField
{
    if (_codeTextField == nil) {
        UITextField *codeTextField = [[UITextField alloc] init];
        [self.view addSubview:codeTextField];
        codeTextField.textColor = [UIColor blackColor];
        codeTextField.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        codeTextField.placeholder = @"请输入验证码";
        codeTextField.backgroundColor = [UIColor clearColor];
        codeTextField.borderStyle = UITextBorderStyleNone;
        codeTextField.textAlignment = NSTextAlignmentLeft;
        codeTextField.keyboardType = UIKeyboardTypeNumberPad;
        codeTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
        codeTextField.keyboardAppearance=UIKeyboardAppearanceDefault;
        codeTextField.returnKeyType =UIReturnKeyDone;
        [codeTextField setClearButtonMode:UITextFieldViewModeNever];
        [codeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.codeLineView);
            make.right.equalTo(self.codeButton.mas_left);
            make.centerY.equalTo(self.codeButton);
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(20)));
            }else{
                make.height.equalTo(@(rate750(20)));
            }
            
        }];
        codeTextField.tintColor = [UIColor blackColor];
        codeTextField.delegate = self;
        _codeTextField = codeTextField;
    }
    return _codeTextField;
}


//提示文字
-(UILabel *)postLabel
{
    if (_postLabel == nil) {
        UILabel *postLabel = [[UILabel alloc] init];
        [self.view addSubview:postLabel];
        postLabel.textColor = NumberColor(129, 128, 129);
        postLabel.text = @"注：请填写与持卡人一致的身份信息";
        postLabel.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        postLabel.textAlignment = NSTextAlignmentLeft;
        [postLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.codeLineView);
            if (isPhoneX) {
                make.top.equalTo(self.codeLineView.mas_bottom).offset(rateX812(20));
            }else{
                make.top.equalTo(self.codeLineView.mas_bottom).offset(rate750(20));
            }
        }];
        _postLabel = postLabel;
    }
    return _postLabel;
}

-(SYNoHeightedButton *)sureButton
{
    if (_sureButton == nil) {
        SYNoHeightedButton *sureButton = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self.view addSubview:sureButton];
        [sureButton setBackgroundImage:[UIImage imageWithColor:zhidianAlprColor(0.3)] forState:UIControlStateDisabled];
        [sureButton setBackgroundImage:[UIImage imageWithColor:zhidainMainColor] forState:UIControlStateNormal];
        [sureButton setTitle:@"确认" forState:UIControlStateNormal];
        [sureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [sureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateDisabled];
        sureButton.titleLabel.font = [UIFont systemFontOfSize:font16ScreenWRate * LKScreenW];
        sureButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        
        [sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.width.equalTo(@(rate375(284)));
            make.centerX.equalTo(self.view);
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(48)));
                make.top.equalTo(self.postLabel.mas_bottom).offset(rateX812(20));
            }else{
                make.height.equalTo(@(rate750(48)));
                make.top.equalTo(self.postLabel.mas_bottom).offset(rate750(20));
            }
            
        }];
        sureButton.enabled = NO;
        [sureButton addTarget:self action:@selector(sureButtonClick:) forControlEvents:UIControlEventTouchDown];
        sureButton.layer.cornerRadius = 5.0f;
        sureButton.layer.masksToBounds = YES;
        
        _sureButton = sureButton;
    }
    return _sureButton;
}

@end
